import vue from 'vue'
import Router from 'vue-router'

//将router注册到全局变量中
//use 是vue中的静态方法。用于将组建注册进vue中
vue.use(Router);

const routes = [
    {
        path: '/thear/:code?',
        component: () => import('./view/thear.vue'),
        meta: {
            title: "风采展示"
        }
    },{
        path: '/heritage/:code?',
        component: () => import('./view/heritage.vue'),
        meta: {
            title: "非遗保护"
        }
    },{
        path: '/volunteers/:code?',
        component: () => import('./view/volunteers.vue'),
        meta: {
            title: "志愿者信息"
        }
    },{
        path: '/news/:code?',
        component: () => import('./view/news.vue'),
        meta: {
            title: "新闻资讯"
        }
    }
];

routes.forEach(route => {
    route.path = route.path || '/' + (route.name || '');
});
const router = new Router({
    routes
});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export {
    router
};
